const DB = require('../../../../utils/db')
const JwtUtil = require('../../../../utils/jwt')
/**
 * GET,
 * 获取好友申请列表
 * 申请添加我为好友
 */

module.exports = async (ctx) => {
  // 获取token
  let token = ctx.request.header.authorization
  let jwt = new JwtUtil(token)
  // 用token获取到userid
  let userid = jwt.verifyToken()
  // 别人申请我为好友
  const applyList = await DB.query(
    `select u.avatar,u.userid,u.username,ua.applyStatus from user_apply ua join user u on ua.applicantid=u.userid where (respondentid='${userid}')`
  )
  ctx.body = {
    code: 0,
    data: applyList,
  }
}
